<template>
  <div class="footer-essay-details">
    <el-form class="essay-details-form" label-width="100px" label-position="right">
      <el-form-item label="文章标题">
        <el-input class="theme-input" v-model="wordManage.title" ></el-input>
      </el-form-item>
      <el-form-item label="所属栏目">
        <!-- <el-select v-model="type">
          <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
          </el-option>
        </el-select> -->
        <div>{{type == 45 ? '关于我们' : '帮助中心'}}</div>
      </el-form-item>
      <el-form-item label="排序">
        <el-input class="theme-input" v-model="num" ></el-input>
      </el-form-item>
      <el-form-item label="内容编辑">
        <wangEditor
          defaultId="company"
          :value="companyEditor"
          @input="html=>{handleEditorChange('company',html)}"
        ></wangEditor>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="e-d-save" @click="save">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import wangEditor from '@/components/wangEditor'
export default {
  data() {
    return {
      wordManage:{
        title:"",
        companyEditor:"",
        to:"",
      },
      num:"",
      options:[{value:45,label:'关于我们'},{value:46,label:'帮助中心'}],
      type:45,
      nameId:-1,
      companyEditor:"",
    }
  },
  components: { wangEditor },
  methods:{
    save(){
      if(this.wordManage.companyEditor == ''){
        this.wordManage.companyEditor = this.companyEditor;
      }
      let url = this.nameId == -1?'/platform/addStaticData.do':'/platform/updateStaticData.do';
      let json = JSON.stringify(this.wordManage);

      let data = new FormData();
      data.append("id",this.nameId+"");
      data.append("content",json);
      data.append("typeId",this.type+"");
      data.append("num",this.num+"");

      this.lAxios({
        method: 'post',
        url:url,
        data,
      }).then(res=>{
        if(res.data.status == 0){
          this.$message.success('操作成功!');
        }else {
          this.$message.error('操作失败!');
        }
      })

    },
    handleEditorChange(p, html) {
      console.log(p)
      console.log(html)
      this.wordManage.companyEditor = html
    },
  },created() {
    if(this.$route.query.hasOwnProperty('row')) {
      let row = this.$route.query.row;
      console.log("row",row)
      this.wordManage.title = row.title;
      this.wordManage.to = row.to;
      this.companyEditor = row.companyEditor;
      this.num = row.num;
      this.nameId = row.id;
    }
    if(this.$route.query.hasOwnProperty('index')) {
      this.type = parseInt(this.$route.query.index);
    }
  }
}
</script>

<style  lang="scss" scoped>
.footer-essay-details {
  width: 100%;
  padding: 30px 20px;
  display: flex;
  justify-content: center;
  .essay-details-form {
    width: 700px;
    .e-d-save {
      width: 300px;
      height: 40px;
      color: #fff;
    }
    .theme-input {
      input {
        width: 300px;
      }
    }
  }
}
</style>
